<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>Sales Forecast</title>
    </h:head>
    <f:view beforePhase="#{UserDisplayManagedBean.initView}">
        <f:view beforePhase="#{SalesForecastManagedBean.initView}">

            <h:form prependId="false">
                <p:growl id="msgs" showDetail="true"/>

                <!-- IDLE DIALOG for -->
                <p:confirmDialog message="You have been idle for 5 minutes. Do you want to continue?"  
                                 showEffect="bounce" hideEffect="explode"  
                                 header="Warning message" severity="alert" widgetVar="confirmation">  
                    <p:commandButton value="Yes" onclick="confirmation.hide()" type="button" /> 
                    <p:commandButton value="No" update="panel" oncomplete="confirmation.hide()"  
                                     actionListener="#{UserManagedBean.doLogout}" /> 
                </p:confirmDialog>

                <p:idleMonitor timeout="300000" onidle="confirmation.show()" />  
                <!--END OF IDLE DIALOG-->
                <h:body>
                    <div id="header">
                        <h:graphicImage value="/image/newHeader.jpg"/>
                    </div>

                    <div id="content">
                        <table>
                            <tr>
                                <td style="vertical-align:top">
                                    <p:toolbar style="background-color:darkred;font-size:90%;height:35px;width:100%"> 
                                        <p:toolbarGroup align="right">
                                            <p:button title="Home" image="ui-icon-home" outcome="ManufacturingDeptWorkspace"/>
                                            <p:button title="Notes" image="ui-icon-note"/>
                                            <p:button title="Mail" image="ui-icon-mail-closed"/>
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar>

                                    <p:menu id="menu" style=" width:205px;height: 555px;font-family: Tahoma;border-style: double;font-size: 80%">  
                                        <p:submenu label="Manufacturing Menu">  
                                            <p:menuitem value="Manufacturing Dept Home" url="http://localhost:8080/MerlionERP-war/MRP/ManufacturingDeptWorkspace.xhtml" ajax="false" icon="ui-icon ui-icon-home"/>  
                                        </p:submenu>
                                        <p:submenu label="Production Planning">
                                            <p:menuitem value="View Sales Record" url="http://localhost:8080/MerlionERP-war/MRP/SalesRecord.xhtml" ajax="false" icon="ui-icon ui-icon-search"/>  
                                            <p:menuitem value="View Sales Forecast" url="http://localhost:8080/MerlionERP-war/MRP/SalesForecast.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="View Sales and Operation Plan" url="http://localhost:8080/MerlionERP-war/MRP/SalesAndOperationPlan.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                        <p:submenu label="Master Production Schedule">
                                            <p:menuitem value="View MPS Weekly" url="http://localhost:8080/MerlionERP-war/MRP/MasterProductionScheduleWeekly.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="View MPS Daily" url="http://localhost:8080/MerlionERP-war/MRP/MasterProductionScheduleDaily.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="Commit MPS" url="http://localhost:8080/MerlionERP-war/MRP/CommitMasterProductionSchedule.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                        <p:submenu label="Material Planning">
                                            <p:menuitem value="View Requirement Planning" url="http://localhost:8080/MerlionERP-war/MRP/MaterialRequirementPlanning.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                        <p:submenu label="Bill of Materials">
                                            <p:menuitem value="View Bill of Materials" url="http://localhost:8080/MerlionERP-war/MRP/BillOfMaterials.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                         <p:submenu label="Production Execution">
                                            <p:menuitem value="Production Execution" url="http://localhost:8080/MerlionERP-war/MRP/ProductionExecution.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                    </p:menu>

                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>

                                <td style=" vertical-align: top">
                                    <h:graphicImage value="salesForecast.jpeg" style="width:35px;height:35px" />
                                    <h:outputText value="         "/>
                                    <h:outputText value="Sales Forecast" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:spacer width="100" height="10"/>

                                    <p:panel id="panel" style=" font-family: Tahoma;width:1105px;height:745px">
                                        <h:panelGrid columns="5">
                                            <h:outputText value="From"/>
                                            <h:outputText value="Month"/>
                                            <h:selectOneMenu value="#{SalesForecastManagedBean.startMonth}">
                                                <f:selectItem itemValue="" itemLabel="Select Month"/>
                                                <f:selectItem itemValue="1" itemLabel="January"/>
                                                <f:selectItem itemValue="2" itemLabel="February"/>
                                                <f:selectItem itemValue="3" itemLabel="March"/>
                                                <f:selectItem itemValue="4" itemLabel="April"/>
                                                <f:selectItem itemValue="5" itemLabel="May"/>
                                                <f:selectItem itemValue="6" itemLabel="June"/>
                                                <f:selectItem itemValue="7" itemLabel="July"/>
                                                <f:selectItem itemValue="8" itemLabel="August"/>
                                                <f:selectItem itemValue="9" itemLabel="September"/>
                                                <f:selectItem itemValue="10" itemLabel="October"/>
                                                <f:selectItem itemValue="11" itemLabel="November"/>
                                                <f:selectItem itemValue="12" itemLabel="December"/>
                                            </h:selectOneMenu>

                                            <h:outputText value="Year"/>
                                            <p:inputText maxlength="4" value="#{SalesForecastManagedBean.startYear}"  
                                                         required="true"/>  

                                            <h:outputText value="To"/>
                                            <h:outputText value="Month"/>
                                            <h:selectOneMenu value="#{SalesForecastManagedBean.endMonth}">
                                                <f:selectItem itemValue="" itemLabel="Select Month"/>
                                                <f:selectItem itemValue="1" itemLabel="January"/>
                                                <f:selectItem itemValue="2" itemLabel="February"/>
                                                <f:selectItem itemValue="3" itemLabel="March"/>
                                                <f:selectItem itemValue="4" itemLabel="April"/>
                                                <f:selectItem itemValue="5" itemLabel="May"/>
                                                <f:selectItem itemValue="6" itemLabel="June"/>
                                                <f:selectItem itemValue="7" itemLabel="July"/>
                                                <f:selectItem itemValue="8" itemLabel="August"/>
                                                <f:selectItem itemValue="9" itemLabel="September"/>
                                                <f:selectItem itemValue="10" itemLabel="October"/>
                                                <f:selectItem itemValue="11" itemLabel="November"/>
                                                <f:selectItem itemValue="12" itemLabel="December"/>
                                            </h:selectOneMenu>

                                            <h:outputText value="Year"/>
                                            <p:inputText maxlength="4" value="#{SalesForecastManagedBean.endYear}"  
                                                         required="true" />  

                                            <h:outputText value="Year-On "/>
                                            <h:outputText value="-Year "/>
                                            <h:outputText value="Growth*"/>
                                            <h:outputText value=":"/>

                                            <p:inputText required="true" requiredMessage="Fill the Growth" value="#{SalesForecastManagedBean.yearOnYearGrowth}"/>

                                            <h:outputText value=""/>
                                            <h:outputText value=""/>
                                            <p:commandButton immediate="false" update="panel forecastMonths" ajax="true" actionListener="#{SalesForecastManagedBean.doRefresh}" type="push" image="ui-icon ui-icon-refresh" value="Refresh Page" />
                                             <h:outputText value=""/>
                                           
                                            <p:commandButton immediate="false" update="panel forecastMonths" ajax="true" actionListener="#{SalesForecastManagedBean.doForecastSales}" type="push" image="ui-icon ui-icon-plus" value="Forecast Sales" />
                                            
                                          </h:panelGrid>

                                        <p:spacer height="50px"/>

                                        <p:dataTable id="forecastMonths" var="forecasts" value="#{SalesForecastManagedBean.selectedForecastMonths}"
                                                     paginator="true" rows="5"
                                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                                     rowsPerPageTemplate="5,10,15"  style="font-size:70%;width:1085px;"
                                                     emptyMessage="No data found with given criteria" widgetVar="forecastSalesTable"
                                                     rowEditListener="#{SalesForecastManagedBean.onEditRow}" 
                                                     selection="#{SalesForecastManagedBean.forecastMonthss}">
                                            <f:facet name="header">
                                                <H2>SALES FORECAST</H2>

                                                <p:outputPanel style="text-align:right"  >
                                                    <h:outputText value="Search all fields:" style="margin-left:740px" />  
                                                    <p:inputText id="globalFilter" onkeyup="forecastSalesTable.filter()" style="right:-100px;width:150px" />  
                                                </p:outputPanel>
                                            </f:facet>
                                            
                                             <p:column style="width: 16px" selectionMode="multiple" />  

                                             <p:column style="width: 100px">
                                                <f:facet name="header">
                                                    <h:outputText value="Year"/>
                                                </f:facet>
                                                <h:outputText value="#{forecasts.yearInt}"/>
                                            </p:column>
                                             
                                            <p:column style="width: 100px">
                                                <f:facet name="header">
                                                    <h:outputText value="Month"/>
                                                </f:facet>
                                                <h:outputText value="#{forecasts.monthInt}"/>
                                            </p:column>

                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Prev Year Sales" />
                                                </f:facet>
                                                <h:outputText value="#{forecasts.previousSales}"/>
                                            </p:column>

                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Prev Year Promotion" />
                                                </f:facet>
                                                <h:outputText value="#{forecasts.previousPromotion}"/>
                                            </p:column>

                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Prev Year Base" />
                                                </f:facet>
                                                <h:outputText value="#{forecasts.previousBase}"/>
                                            </p:column>

                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Growth" />
                                                </f:facet>
                                                <h:outputText value="#{forecasts.growth}"/>
                                            </p:column>

                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Base Projection" />
                                                </f:facet>
                                                <h:outputText value="#{forecasts.projectedBase}"/>
                                            </p:column>

                                            <p:column headerText="Promotion">
                                                <p:cellEditor>
                                                    <f:facet name="output">
                                                        <h:outputText value="#{forecasts.projectedPromotion}" />
                                                    </f:facet>
                                                    <f:facet name="input">
                                                        <p:inputText style="width:50px" value="#{forecasts.projectedPromotion}">
                                                            <p:ajax event="rowEdit" update="sf"/>
                                                        </p:inputText>
                                                    </f:facet>
                                                </p:cellEditor>
                                            </p:column>

                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Sales Forecast" />
                                                </f:facet>
                                                <h:outputText id="sf" value="#{forecasts.projectedSales}"/>
                                            </p:column>
                                            
                                            
                                            
                                             <p:column headerText="Status" style="width: 100px">
                                                 <h:outputText value="Finalized" rendered="#{forecasts.forecasted}"/>
                                                 <h:outputText value="Not Finalized" rendered="#{!forecasts.forecasted}"/>
                                             </p:column>

                                            <!--EDIT-->   
                                            <p:column style=" border-left-color:transparent;border-right-color:transparent">
                                                <f:facet name="header">
                                                    <h:outputText value="Edit"/>
                                                </f:facet>
                                                <p:rowEditor  />
                                            </p:column>
                                        </p:dataTable>
                                         <p:commandButton immediate="false" update="msgs panel forecastMonths" ajax="true"  actionListener="#{SalesForecastManagedBean.doFinalize}" type="push" image="ui-icon ui-icon-document" value="Finalize Plans" />
                                        
                                         <p:commandButton immediate="false" update="msgs panel forecastMonths" ajax="true"  actionListener="#{SalesForecastManagedBean.doDefinalize}" type="push" image="ui-icon ui-icon-document" value="Definalize Plans" />
                                      
                                    </p:panel>
                                </td>
                            </tr>
                        </table>
                    </div>

                    <div id="footer">
                        <h:graphicImage value="/image/merlionfooter.jpg"/>
                    </div>
                </h:body>
            </h:form>
        </f:view>
    </f:view>
</html>

